package cn.tedu._05mvcboot03.common.exeception;

import cn.tedu._05mvcboot03.common.response.JsonResult;
import cn.tedu._05mvcboot03.common.response.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@Slf4j
@RestControllerAdvice
public class Globol {
    @ExceptionHandler
    public JsonResult doMethodArgumentNotValidException(MethodArgumentNotValidException ex){
        String message=ex.getFieldError().getDefaultMessage();
        log.error("message:{}",message);
        return  new JsonResult(StatusCode.VALIDATED_ERROR,message);
    }
}
